<?php
/**
 * Created by phpstrom.
 * User:wangyahe
 * Date: 2017/6/5
 * Time: 21:07
 */
namespace app\admin\controller;
use system\model\Admin;
class Login
{
	public function index(Admin $admin){
		//测试password_hash函数，php手册中搜索password就能搜索到
//    	$password = password_hash('admin888',PASSWORD_DEFAULT);
//    	echo $password;
//    	$bool = password_verify('admin8885',$password);
//    	dd($bool);
//		die;

		//测试数据库的链接
//		$res = Db::table('admin')->get();
//		p($res);die();
//		$res = (new Admin())->get();
//		p($res);
		if(IS_POST){
			$adminModel=$admin->login();
//			if($adminModel['valid'])
//			{
//				//执行成功
//				message( $adminModel['msg'], u('admin.entry.index'), $type = 'success', $timeout = 2 );
//			}else{
//				//执行失败
//				message($adminModel['msg'],'back','error');
//			}
			$res = $admin->login();
			if($res['valid'])
			{
				//执行成功
				return message($res['msg'],'admin.entry.index','success');
//				return ['valid'=>1,'message'=>$res['msg']];
			}else{
				//执行失败
				return message($res['msg'],'back','error');
				//return ['valid'=>0,'message'=>$res['msg']];

			}
		}
//		p(Crypt::encrypt('admin888'));die();
//		h3vPU8JGuF3VS/uxIpjRSw==
//		Gw7yHXj+AS8VPYVOeHNHHA==
		//加载模板文件

		return View::make();
	}

	//加载验证码函数
	public function code(){
		Code::width(100)->height(50)->num(1)->make();
	}

	//退出的函数
	public function out(){
		//清除掉所有的session
		Session::flush();
		//进行跳转,退出页面以后进行跳转
		go(__ROOT__.'/index.php/login');
	}





}